    //Random Game Engine
    //Copyright (C) 2012  Nikolay Dionisov

    //This program is free software: you can redistribute it and/or modify
    //it under the terms of the GNU General Public License as published by
    //the Free Software Foundation, either version 3 of the License, or
    //(at your option) any later version.

    //This program is distributed in the hope that it will be useful,
    //but WITHOUT ANY WARRANTY; without even the implied warranty of
    //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    //GNU General Public License for more details.

    //You should have received a copy of the GNU General Public License
    //along with this program.  If not, see <http://www.gnu.org/licenses/>.

	//------------------------------------------------------------------------

	//FILE NAME: ThreadPool.h
	//Shows how to use RealtimeDataTypes.h and implements really simple(add,remove) list of processes.
	//Definitions of templates and interfaces for easier use(instantiate template or inherite)

#pragma once
#include "..\BasicTypes\BaseTypes.h"
#include "RealtimeDataTypes.h"
#include <memory>
namespace re
{
	namespace core
	{
		class IRealtimeProcess
		{
		public:
			IRealtimeProcess() {}
			~IRealtimeProcess() {}
			virtual void MainLoop() = 0;
		};
		class RealtimeProcess : public IRealtimeProcess
		{
		public:
			RealtimeProcess() { alive_ = true;}
			~RealtimeProcess() {}
			void MainLoop()
			{
				Initialize();
				while(alive_)
				{
					Update();
				}
				ShutDown();
			}
		protected:
			bool alive_;
			virtual void Update() = 0;
			virtual void Initialize() = 0;
			virtual void ShutDown() = 0;
		};
		typedef std::tr1::shared_ptr<IRealtimeProcess> RealtimeProcessPtr;
		class ThreadPool
		{
		public:
			ThreadPool() {}
			~ThreadPool() {}

			bool AttachThread(RealtimeProcessPtr thread);
			bool DetachThread(RealtimeProcessPtr thread);
			RealtimeList<RealtimeProcessPtr> processes_;
		};
	}
}